<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>asynctestcase.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">asynctestcase.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    A class representing a set of test functions that use
 asynchronous functions that cannot be meaningfully mocked.

 To create a Google-compatable JsUnit test using this test case, put the
 following snippet in your test:

 var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();

 To make the test runner wait for your asynchronous behaviour, use:

 asyncTestCase.waitForAsync(&amp;#39;Waiting for xhr to respond&amp;#39;);

 The next test will not start until the following call is made, or a
 timeout occurs:

 asyncTestCase.continueTesting();

 There does NOT need to be a 1:1 mapping of waitForAsync calls and
 continueTesting calls. The next test will be run after a single call to
 continueTesting is made, as long as there is no subsequent call to
 waitForAsync in the same thread.

 Example:
 // Returning here would cause the next test to be run.
 asyncTestCase.waitForAsync(&amp;#39;description 1&amp;#39;);
 // Returning here would *not* cause the next test to be run.
 // Only effect of additional waitForAsync() calls is an updated
 // description in the case of a timeout.
 asyncTestCase.waitForAsync(&amp;#39;updated description&amp;#39;);
 asyncTestCase.continueTesting();
 // Returning here would cause the next test to be run.
 asyncTestCase.waitForAsync(&amp;#39;just kidding, still running.&amp;#39;);
 // Returning here would *not* cause the next test to be run.

 This class supports asynchronous behaviour in all test functions except for
 tearDownPage. If such support is needed, it can be added.

 Example Usage:

 var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
 // Optionally, set a longer-than-normal step timeout.
 asyncTestCase.stepTimeout = 30 * 1000;

 function testSetTimeout() {
 var step = 0;
 function stepCallback() {
 step++;
 switch (step) {
 case 1:
 var startTime = goog.now();
 asyncTestCase.waitForAsync(&amp;#39;step 1&amp;#39;);
 window.setTimeout(stepCallback, 100);
 break;
 case 2:
 assertTrue(&amp;#39;Timeout fired too soon&amp;#39;,
 goog.now() - startTime &amp;gt;= 100);
 asyncTestCase.waitForAsync(&amp;#39;step 2&amp;#39;);
 window.setTimeout(stepCallback, 100);
 break;
 case 3:
 assertTrue(&amp;#39;Timeout fired too soon&amp;#39;,
 goog.now() - startTime &amp;gt;= 200);
 asyncTestCase.continueTesting();
 break;
 default:
 fail(&amp;#39;Unexpected call to stepCallback&amp;#39;);
 }
 }
 stepCallback();
 }

 Known Issues:
 IE7 Exceptions:
 As the failingtest.html will show, it appears as though ie7 does not
 propagate an exception past a function called using the func.call()
 syntax. This causes case 3 of the failing tests (exceptions) to show up
 as timeouts in IE.
 window.onerror:
 This seems to catch errors only in ff2/ff3. It does not work in Safari or
 IE7. The consequence of this is that exceptions that would have been
 caught by window.onerror show up as timeouts.
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_testing_asynctestcase.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/closure/goog/testing/asynctestcase.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">testing/asynctestcase.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_testing_AsyncTestCase.html">
          goog.testing.AsyncTestCase</a><br/>
        <div class="class-details">A test case that is capable of running tests the contain asynchronous logic.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_testing_AsyncTestCase_ControlBreakingException.html">
          goog.testing.AsyncTestCase.ControlBreakingException</a><br/>
        <div class="class-details">An exception class used solely for control flow.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.testing.AsyncTestCase.call"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.AsyncTestCase.</span><span class="entryName">call<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_asynctestcase.js.source.html#line117">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.testing.AsyncTestCase.createAndInstall"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.AsyncTestCase.</span><span class="entryName">createAndInstall<span class="args">(<span class="arg">opt_name</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type"><a href="class_goog_testing_AsyncTestCase.html">goog.testing.AsyncTestCase</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
      </div>


     <div class="entryOverview">
       Preferred way of creating an AsyncTestCase. Creates one and initializes it
with the G_testRunner.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">opt_name</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span><span>&nbsp;|&nbsp;</span><span class="type">undefined</span>)</div>
        <div class="entryOverview">A descriptive name for the test case.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type"><a href="class_goog_testing_AsyncTestCase.html">goog.testing.AsyncTestCase</a></span><span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>&nbsp;
            The created AsyncTestCase.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_asynctestcase.js.source.html#line326">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.testing.AsyncTestCase.ControlBreakingException.TO_STRING"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.AsyncTestCase.ControlBreakingException.</span><span class="entryName">TO_STRING</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Return value for .toString().
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_testing_asynctestcase.js.source.html#line150">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory testing</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="testing/asynctestcase.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
